﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Demo6
{
    /// <summary>
    /// 
    /// </summary>
    class Program
    {
        static void Main(string[] args)
        {
            //定义交叉数组：1. 双中括号[][]  2.第一维度必须确定大小
            string[][] cities = new string[][] {
                new string []{ "广西壮族自治区","南宁市","柳州市","桂林市","梧州市","北海市","防城港市","钦州市","贵港市","玉林市","百色市",
                "贺州市","河池市","来宾市","崇左市" },
                new string[] { "广东省","广州市","珠海市","东莞市","佛山市","中山市","惠州市","汕头市","江门市","湛江市","肇庆市","梅州市","茂名市",
                "阳江市","清远市","韶关市","揭阳市","汕尾市","潮州市","河源市","云浮市" },
                new string[] { "湖南省", "长沙", "株洲", "湘潭", "衡阳", "邵阳", "岳阳", "常德", "张家界", "益阳", "郴州", "永州", "怀化", "娄底和湘西土家族苗族自治州" },
        };
            // 输出所有省和它对应的城市
            // 遍历数组的行，再遍历每行中的列
            for(int i=0; i<cities.GetLength(0);i++)
            {
                // 交叉数组中表示第i行的第1列 [i][0], 不能用[i,0]
                Console.Write($"{cities[i][0]}：");
                // 输出城市，遍历第i行的 第二个元素到最后一个元素
                for (int j = 1; j < cities[i].Length; j++)
                    Console.Write($"{cities[i][j]} ");

                Console.WriteLine();
            }

            //cities[0][1] = "南宁";
            // 把以上城市名称中的”市“都去掉
            for (int i = 0; i < cities.GetLength(0)-1; i++)
            {
                for (int j = 1; j < cities[i].Length; j++)
                {
                    //把市字去掉 Substring(0, str.Length - 1);
                    cities[i][j] = cities[i][j].Substring(0, cities[i][j].Length - 1);
                }
            }


            Console.WriteLine("\n修改数组后的输出结果：");
            for (int i = 0; i < cities.GetLength(0); i++)
            {
                // 交叉数组中表示第i行的第1列 [i][0], 不能用[i,0]
                Console.Write($"{cities[i][0]}：");
                // 输出城市，遍历第i行的 第二个元素到最后一个元素
                for (int j = 1; j < cities[i].Length; j++)
                    Console.Write($"{cities[i][j]} ");

                Console.WriteLine();
            }

            // 输入一个省名称，输出城市
            Console.Write("请输入一个省份：");
            string kw = Console.ReadLine();
            for (int i = 0; i < cities.GetLength(0); i++)
            {
                // Contain字符串是否包含
                if(cities[i][0].Contains(kw))
                {
                    Console.Write($"{cities[i][0]}的城市有：");
                    for (int j = 1; j < cities[i].Length; j++)
                        Console.Write($"{cities[i][j]} ");

                    Console.WriteLine();
                }
            }

            Console.ReadKey();
        }
    }
}
